package com.woniu.smart.exception;

import com.woniu.smart.util.Result;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description: 自定义全局异常
 * @Author: WangHeng
 * @Date: 2022/10/30 20:58
 */
@RestControllerAdvice
public class ValidExceptionHandler {
    @ExceptionHandler(BindException.class)
    public Result validExceptionHandler(BindException exception) {
        return Result.error(exception.getBindingResult().getFieldError().getDefaultMessage());
    }
}
